<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>材料供货单供货确认审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../resources/css/style.css">
    <style>
        .details ul li {width: 50%;float: left;}
        .layui-table thead th{text-align: left;}
        /*thead tr th:before {content: "● "; color: #e3e3e3; font-size: 12px;}*/
        .layui-table td{text-indent: 1rem; font-size: 12px; color: #333;text-indent: 0;}
        .titles{text-align: center;font-size: 20px;}
        ._sumb{text-align: right;}
        body{position: relative;bottom: 60px;}
        /*tbody{padding-bottom: 200px!important;}*/
        .detaileds{padding-bottom: 100px!important;}
        @media screen and (max-width: 768px) {
            body{bottom: 0;}
            .details ul{margin-top: 0;}
            ._MOVE .details ul li{width: 100%;}
            ._MOVE .details .detaL{width: 30%;padding: 0;}
            ._MOVE .details .detaR{width: 70%;padding: 0;}
            ._MOVE .detaileds{width: 100%;overflow-x: auto;}
            ._MOVE .detaileds table{width: 200%!important;overflow-x: auto;}
            ._MOVE .detaileds table thead th, ._MOVE .detaileds table tbody td{width: auto;padding:10px 0;text-align:
                    left;}
            ._MOVE .detaileds table tbody td{text-indent: 1em;}
            .MOVE_title{top: 0;}
            .MOVE_title .shousuo{margin-right: 22px;}
            .tijiao{position: absolute;top: 0;right: 0; background-color: transparent;border: 0;font-size: 20px;
                height: 45px; line-height: 45px;margin-right: 15px!important;color: #FFF;}
        }

        .detaileds{width: 100%;overflow: auto;}
/*        .detaileds table{width: 140%!important;}*/
        ._PC{margin-top: 60px;}
        .yujing table th,td{text-align: center;}
        .ys{
           color: #fff;
        }
    </style>
</head>
<body>
<div class="_PC">
    <form class="layui-form layui-form-pane" action="" >
        <button class="layui-btn" type="button" onclick="history.back(-1);"><i class="layui-icon"></i></button>

        <div class="engineering"><!--工程信息-->
            <div class="titles">施工单位申请单</div>
            <div class="details">
                <!--<ul>-->
                <!--<li><span class='detaL'>项目名称：</span><span class="dataR">  西三环通讯管道施工 </span></li>-->
                <!--<li><span class='detaL'>状态：</span><span class="dataR">尚未供料</span></li>-->
                <!--<li><span class='detaL'>施工单位：</span><span class="dataR"> 厂北路-郑上路</span></li>-->
                <!--<li><span class='detaL'>供货地址：</span><span class="dataR">郑州市金水路花园路</span></li>-->
                <!--<li><span class='detaL'>供货时间：</span><span class="dataR">2017年7月15日</span></li>-->

                <!--</ul>-->
            </div>
            <div class="yujing">
                <div class="titles">材料预警</div>
                <table class="layui-table">
                    <thead>
                        <tr>
                            <th>材料类型</th>
                            <th>是否超出</th>
                            <th>剩余材料量</th>

                        </tr>
                    </thead>
                    <tbody>
                        <!--<tr>-->
                            <!--<td>1</td>-->
                            <!--<td>1</td>-->
                            <!--<td>1</td>-->
                        <!--</tr>-->
                    </tbody>

                </table>

            </div>

            <div class="detailed">      <!--材料明细-->
                <div class="titles">需求申请单</div>

                <div class="detaileds">
                    <table class="layui-table">

                        <thead>
                        <tr>
                            <th>材料名称</th>
                            <th >材料规格</th>
                            <th >材料单位</th>
                            <th>单价</th>
                            <th>申请数量</th>
                            <th class="ys">送料数量</th>
                            <th class="ys">签收数量</th>
                            <th>录入人</th>
                            <th >审核数量</th>
                            <th >质量审核</th>
                            <th >备注</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!--<tr>-->
                        <!--<td>三级钢</td>-->
                        <!--<td>28</td>-->
                        <!--<td>t</td>-->
                        <!---->
                        <!--</tr>-->

                        </tbody>
                    </table>
                </div>



            </div>
            <!--<div class="detailed">      &lt;!&ndash;材料明细&ndash;&gt;-->
            <!--<div class="titles">材料供应单（单号：F635）</div>-->

            <!--<div class="detaileds">-->
            <!--<table class="layui-table">-->
            <!--<colgroup>-->
            <!--<col width="150">-->
            <!--<col width="150">-->
            <!--<col width="150">-->
            <!--<col width="150">-->
            <!--<col width="150">-->
            <!--<col width="150">-->
            <!--<col width="150">-->
            <!--</colgroup>-->
            <!--<thead>-->
            <!--<tr>-->
            <!--<th>材料名称</th>-->
            <!--<th>材料规格</th>-->
            <!--<th>数量</th>-->
            <!--</tr>-->
            <!--</thead>-->
            <!--<tbody>-->
            <!--<tr>-->
            <!--<td>三级钢</td>-->
            <!--<td>28</td>-->
            <!--<td>t</td>-->

            <!--</tr>-->
            <!--<tr>-->
            <!--<td>三级钢</td>-->
            <!--<td>28</td>-->
            <!--<td>t</td>-->

            <!--</tr>-->
            <!--<tr>-->
            <!--<td>三级钢</td>-->
            <!--<td>28</td>-->
            <!--<td>t</td>-->

            <!--</tr>-->

            <!--</tbody>-->
            <!--</table>-->
            <!--</div>-->



            <!--</div>-->

        </div>

        <div class="_sumb">
            <button class="layui-btn layui-btn-sm  tijiao" lay-submit lay-filter="_subm">提交</button>
        </div>
    </form>
</div>
<script src="../../../resources/layui/layui.js" charset="utf-8"></script>
<script src="../../../resources/js/style.js"></script>
<script src="../../../resources/js/api.js"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date1'      //开始时间
        });
        laydate.render({
            elem: '#date2'  //结束时间
        });

        ajaxs('/api/matperson/loadghMoudle.do','post',{'type':'c','remark':sessionStorage.uuid,'cc_uuid':sessionStorage.cc_uuid,'p':getCookie('yanzheng')},function
        (data) {
            console.log(data)
            var datas=data.data;
            for(var i=0;i<datas.length;i++){
                if(i==0){                   //页面公共部分 只选择一次渲染
                    $('.details').append(' <ul>\n' +
                        '                <li><span class=\'detaL\'>项目名称：</span><span class="dataR">'+datas[i].eppName+'('+datas[i].eppStaEnd+')'+'</span></li>\n' +
                        '                <li><span class=\'detaL\'>施工单位：</span><span class="dataR"> '+datas[i].compName1+'</span></li>\n' +
                        '                <li><span class=\'detaL\'>收货地址：</span><span class="dataR">'+datas[i].r_adr+'</span></li>\n' +
                        '                <li><span class=\'detaL\'>供货时间：</span><span class="dataR">'+datas[i].updateTime+'</span></li>\n' +
                        '            </ul>')


                };
                switch (datas[i].validate){
                    case 0:
                        datas[i].validate='已审核';
                        break;
                    case -1:
                        datas[i].validate='未审核';
                        break;
                    case 1:
                        datas[i].validate='审核不通过';
                        break;

                };
                var xiaoji=0;
                datas[i].mat_Bit=='根'?xiaoji=datas[i].old_Price*datas[i].fin_Num*6:xiaoji=datas[i].old_Price*datas[i].fin_Num;
                $('.detaileds tbody').append(' <tr id="'+datas[i].id+'" mat="'+datas[i].mat_Type+'">\n' +
                    '                        <td>'+datas[i].mat_Name+'</td>\n' +
                    '                        <td>'+datas[i].mat_Spec+'</td>\n' +
                    '                          <td>'+datas[i].mat_Bit+'</td>       \n' +
                    '                         <td>'+datas[i].old_Price+'</td>\n' +
                    '                        <td>'+datas[i].fin_Num+'</td>\n' +
                    '                         <td class="ys">'+datas[i].send_Num+'</td>\n' +
                    '                         <td class="ys">'+datas[i].rm_Num+'</td>\n' +
                    '                        <td>'+datas[i].createUser+'</td>\n' +
                    '                        <td style="width: 80px;"> <input type="number" name="WSNum" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="'+datas[i].rm_Num+'"></td>' +
                    '                        <td style="width: 80px;"> <select name="modules"  lay-verify="required" lay-search="">\n' +
                    '          <option value="0">合格</option>\n' +
                    '          <option value="1">不合格</option>\n' +

                    '        </select></td>\n' +
                    '                        <td style="width: 80px;"><input type="text" lay-verify="required" name="WSbeizhu" placeholder="请输入" autocomplete="off" class="layui-input" value="正常"></td>' +
                    '                    </tr>');
                form.render();
            }

            var arrs1=[];
            var k = 0, j = 0;
            var nums;
            var material={};
            //拿总的
            $(data.fullDown.message[0]).each(function (i,item) {
                    var key = item.cc_key;
                    var value = item.cc_value;


                    if ( key.indexOf("直") > 0 || key.indexOf("梅") > 0 ){
                        var z=/(\d*)[^\d]*/ig;
                        var zongnums=0;

                        nums=key.replace(/[^0-9]+/g, ',');
                        nums=nums.substring(0,nums.length-1);
                        nums=nums.split(',');
                        for(var i=0;i<nums.length;i++){
                            zongnums+=Number(nums[i]);
                        }
                        console.log(z.exec(key),'||')
                        //km情况
                        value = zongnums * parseFloat(value) * 1000 ; // m
                        k += value;
                    }else {
                        value = parseFloat(value); //座
                        j += value;
                    }
            });
            var d = {"kong":k,"j":j};
            console.log(d,">>>>>>>>>>>>>>>>>>>>>>>")
            //拿细项的
            var kaicao;
            var renshou;
            $(data.fullDown.message[1]).each(function (i,item) {
                var key = item.mat_Bit.toString().toLowerCase();
                var value = parseFloat( item.allNum );
                var overflowNum=0;

                if ( key.indexOf("根")!=-1 || key.indexOf( "m" )!=-1 ||key.indexOf( "米" )!=-1 || key.indexOf( "km" )!=-1  || key.indexOf("公里")!=-1 ){
                    var vali = 0; //0代表够,1代表超出
                    if ( key.indexOf("根")!=-1 ){
                        vali = d.kong - ( value * 6 ) > 0 ? 0 : 1;
                        overflowNum=d.kong - value ;
                        console.log(overflowNum,'1');

                    }else if ( key.indexOf( "m" )!=-1 ){
                        vali = d.kong > value ? 0 : 1;
                        overflowNum=d.kong-value;
                        console.log(overflowNum,'2');

                    }else if ( key.indexOf( "km" )!=-1 || key.indexOf("公里")!=-1 ){
                        vali = d.kong - ( value * 1000 ) > 0 ? 0 : 1;
                        overflowNum=d.kong - ( value * 1000 );
                        console.log(overflowNum,'3');

                    }else if(key.indexOf( "米" )!=-1){
                        vali = d.kong > value ? 0 : 1;
                        overflowNum=d.kong-value;
                        console.log(overflowNum,'4');
                    }
                    kaicao=vali;
                    console.log(item.p_name,"  是否超出：  ",kaicao);
                    if(kaicao==1){
                        arrs1.push(item.mat_Type);
                    }
                    var a=item.p_name;
                    material[a+'('+item.mat_Bit+')']=[kaicao,overflowNum];

                }else {
                    //0代表够,1代表超出
                    var vali = k.j > value ? 0 : 1;
                    renshou=vali;
                    if(renshou==1){
                        arrs1.push(item.mat_Type);
                    }
                    console.log(item.p_name," 是否超出：  ",renshou);
                    var a=item.p_name;
                    material[a]=[renshou,overflowNum];


                }

                console.log(material,'?>?>?>?>?>?>?>');

                console.log(arrs1,'?>?>?>?>?>?>?>');
                $('.detaileds tbody tr').each(function (k,v) {

                    for(var i=0;i<arrs1.length;i++){
                        if($(v).attr('mat')==arrs1[i]){
                            $(v).css('border','2px solid red');
                        }
                    }
                })

            });
            for(var key in material){
                console.log(material[key])
                var d=material[key][0];
                d==0?d='未超出':d='已超出';
                $('.yujing tbody').append('<tr>\n' +
                    '                            <td>'+key+'</td>\n' +
                    '                            <td>'+d+'</td>\n' +
                    '                            <td>'+Math.abs(material[key][1]).toFixed(4)+'</td>\n' +
                    '                        </tr>')



            }

        })

        form.on('submit(_subm)',function (data) {
            //console.log(data.field)
            var cailiao='';
            $('._PC .detaileds tbody tr').each(function () {
                cailiao+=$(this).attr('id')+','+$(this).children().children('[name="WSNum"]').val()+','+$(this).children().children('[name="modules"]').val()+','+$(this).children().children('[name="WSbeizhu"]').val()+'|'

            });

            cailiao=cailiao.substr(0,cailiao.length-1);         //删除最后一个|
            //console.log(cailiao)
            var arrs=getCookie('yanzheng');
            arrs=arrs.split('|');


            data.field.paramStr=cailiao;
            data.field.rm_code= sessionStorage.danhao;
            data.field.valiPerson=arrs[0];
            data.field.p=getCookie('yanzheng');

            Btnon('.tijiao');
            tiaoAlertAjax('/api/buil/builGhVali.do',data.field,'.tijiao');


            return false;
        })

    })

</script>
</body>
</html>